<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="年份" prop="orderyear">
        <el-date-picker
          v-model="queryParams.orderyear"
          type="year"
          value-format="yyyy"
          placeholder="请选择年份"
          clearable
          size="small"
         :picker-options="orderyear"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
     <el-form-item label="月份" prop="ovmonth">
        <el-select v-model="queryParams.ovmonth" placeholder="请选择" style="width: 170px">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
      <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:order:remove']"
          >删除</el-button
        >
      </el-col>
      
    </el-row>

    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderCode" />
      <el-table-column
        label="成本类型"
        align="center"
        prop="orderCostType"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="订单名称" align="center" prop="orderName" />
      <el-table-column
        label="产值"
        align="center"
        prop="countOutPutMoney"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="借款"
        align="center"
        prop="countBorrowAmount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="报销"
        align="center"
        prop="countRAmount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="工资"
        align="center"
        prop="salaryCount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="产值成本比"
        align="center"
        prop="costRatio"
        :show-overflow-tooltip="true"
      />
      <!-- </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单年份" prop="orderyear">
          <el-date-picker
            v-model="form.orderyear"
            type="year"
            value-format="yyyy"
            placeholder="选择年"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单号" prop="dname">
          <el-input v-model="form.dname" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="成本类型" prop="orderCostType">
          <el-input v-model="form.orderCostType" placeholder="请输入成本类型" />
        </el-form-item>
        <el-form-item label="订单名称" prop="address">
          <el-input v-model="form.address" placeholder="请输入订单名称" />
        </el-form-item>
        <el-form-item label="产值" prop="ordercode">
          <el-input v-model="form.ordercode" placeholder="请输入产值" />
        </el-form-item>
        <el-form-item label="借款" prop="ordername">
          <el-input v-model="form.ordername" placeholder="请输入借款" />
        </el-form-item>
        <el-form-item label="报销" prop="ordername">
          <el-input v-model="form.ordername" placeholder="请输入报销" />
        </el-form-item>
        <el-form-item label="工资" prop="orderType">
          <el-input v-model="form.orderType" placeholder="请输入工资" />
        </el-form-item>
        <el-form-item label="产值成本比" prop="orderproportion">
          <el-input
            v-model="form.orderproportion"
            placeholder="请输入产值成本比"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrderkpi,
  getOrderkpi,
  delOrderkpi,
  addOrderkpi,
  updateOrderkpi,
  exportOrderkpi,
} from "@/api/system/orderkpi";

export default {
  name: "Orderkpi",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      names: [],
      orderids: [],
      // 非单个禁用
      single: true,
      //新增禁用
      add:false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderyear: null,
        orderCode: null,
        orderName: null,
        countOutPutMoney: null,
        countBorrowAmount: null,
        countRAmount: null,
        salaryCount: null,
        costRatio: null,
        ordername: null,
        did: null,
        dname: null,
        userid: null,
        username: null,
        userid2: null,
        ordertype: null,
        ordersdate: null,
        orderedate: null,
        orderdate: null,
        orderyear: null,
        corpid: null,
        orderstate: null,
        address: null,
        orderCostType: null,
        orderproportion: null,
        salestarget: null,
        businesstype: null,
        customer: null,
        isActive: null,
        wtrmanager: null,
        wtrmanagerid: null,
        orderType: null,
      },
      orderyear: "",
      //查询月份
      options: [
        {
          value: "1",
          label: "1",
        },
        {
          value: "2",
          label: "2",
        },
        {
          value: "3",
          label: "3",
        },
        {
          value: "4",
          label: "4",
        },
        {
          value: "5",
          label: "5",
        },
        {
          value: "6",
          label: "6",
        },
        {
          value: "7",
          label: "7",
        },
        {
          value: "8",
          label: "8",
        },
        {
          value: "9",
          label: "9",
        },
        {
          value: "10",
          label: "10",
        },
        {
          value: "11",
          label: "11",
        },
        {
          value: "12",
          label: "12",
        },
      ],
      value: "",
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderyear: [
          //{required:true,message:"年份不能为空",trigger:"blur"},
          // pattern:,
          //massege:"请输入正确的格式",
          //trigger:"blur"
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrderkpi(this.queryParams).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderid: null,
        orderyear: null,
        orderCode: null,
        orderName: null,
        countOutPutMoney: null,
        countBorrowAmount: null,
        countRAmount: null,
        salaryCount: null,
        costRatio: null,
        ordername: null,
        did: null,
        dname: null,
        userid: null,
        username: null,
        userid2: null,
        ordertype: null,
        ordersdate: null,
        orderedate: null,
        orderdate: null,
        corpid: null,
        orderstate: null,
        address: null,
        orderCostType: null,
        orderproportion: null,
        salestarget: null,
        businesstype: null,
        customer: null,
        isActive: null,
        wtrmanager: null,
        wtrmanagerid: null,
        orderType: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderid);
      this.names = selection.map((item) => item.ordername);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;

      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderid = row.orderid || this.ids;
      getOrder(orderid).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.orderid != null) {
            updateOrder(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addOrder(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      console.log("1", this.names);
      let params = {};
      if (row.bubbles) {
        params = this.names;
      } else {
        params = row.ordername;
      }
      // const ids=row.id||this.ids;
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单名称为"' + params + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delOrder(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有订单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportOrder(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {});
    },
  },
};
</script>
